<?php

declare(strict_types=1);
/**
 * This file is part of habo_new_media.
 *
 * @link     https://www.berlen.cn/
 * @contact  tech@berlen.cn
 * @license  http://gitlab.rehou.cn/habo/habo_new_media/-/blob/master/README.md
 */
namespace app\service\analysis\data\material\pic;

use app\model\mongo\MongoMaterialPicMonthStatModel;
use app\service\analysis\data\material\stat\AreaMonthStatTrait;
use app\service\BaseService;

class PicAreaMonthStatService extends BaseService
{
    use AreaMonthStatTrait;

    public function __construct(array $arr = [])
    {
        $this->taskType = intval($arr[2] ?? 0);
        $this->areaId = intval($arr[1] ?? 0);
        $this->statMonth = intval($arr[0] ?? 0);
    }

    /**
     * 获取区域图片月汇总数据.
     * @param array $data 更新数据
     */
    protected function getAreaMonthStatField(array $data = []): array
    {
        // 消耗查询
        $map = [
            ['area_id', '=', $this->areaId],
            ['stat_month', '=', $this->statMonth],
        ];

        $data['qq']['cost'] = (new MongoMaterialPicMonthStatModel())->where($map)->sum('qq.cost');
        $data['oe']['cost'] = (new MongoMaterialPicMonthStatModel())->where($map)->sum('oe.cost');
        $data['ks']['cost'] = (new MongoMaterialPicMonthStatModel())->where($map)->sum('ks.cost');
        return $data;
    }
}
